#
# commands.py - these are commands that are to be interpreted by CI and translated
#  into server commands which can be used to populate L1
#
# Commands have to take at least two variables - a WMI world and a L1 player

from math import *

def goToBall(world, player, distance=2):
	"This function takes the player to the ball"
	pass

def idle(world, player):
	turn(world, player, 10)
	player.push(['dash 30'])
	player.push(['dash 30'])
	player.push(['dash 30'])
	pass

def goTo(world, player, loc=None, speed=0.5, precision=3):
	"""Moves player to loc"""
	if loc==None: loc = world.home
	
	target_direction, target_distance = world.to(loc)
	
	if target_direction == None:
		return
	else:
		# print type(player) "Current dir:", world.world.context.direction, "Target dir:", target_direction
		turn(world, player, target_direction - world.world.context.direction)
	
def turn(world, player, angle):
	"""Turns player by angle degrees"""
	player.push(['turn', str(angle)], turn_cb, [world, angle])
	
def turn_cb(world, angle):
	"""Callback to update world"""
	world.world.context.direction += float(radians(angle))
	# print "Turned by", angle, "degrees. New angle is", degrees(world.world.context.direction), "degrees."
